//api接口统一管理模块
import requests from "./request";
import mockAjax from "./mockajax";

//三级联动模块的API请求 :   /api/product/getBaseCategoryList   GET请求  无任何参数

export const getBaseCategoryList = () => {
    //axios返回的是Promise对象
    return requests({ url: "/product/getBaseCategoryList", method: "GET" })
}

// 获取mock的假数据
export const reqGetBannner = () => mockAjax.get("/banner");

export const reqfloorGet = () => mockAjax.get("/floor");


// 获取搜索的数据,这个请求就是要带参数，其中参数例子为
// {
//     "category3Id": "61",
//         "categoryName": "手机",
//             "keyword": "小米",
//                 "order": "1:desc",
//                     "pageNo": 1,
//                         "pageSize": 10,
//                             "props": ["1:1700-2799:价格", "2:6.65-6.74英寸:屏幕尺寸"],
//                                 "trademark": "4:小米"
// }

// 其中这个请求为一个必须要带一个空对象【（params）为空对象】，不然请求会失败


export const SearchList = (params) => {
    return requests({ url: '/list', method: 'POST', data: params })
}


//获取详细列表的数据，
//其中skuId是商品的id
export const DetailList = (skuId) => {
    return requests({ url: `/item/${skuId}`, method: 'GET' })
}

// 添加购物车的请求
//其中skuId是商品的id，skuNum是商品的数据,
//其中这个是修改数量的一个接口
export const addToCart = (skuId, skuNum) => {
    return requests({ url: `/cart/addToCart/${skuId}/${skuNum}`, method: "POST" });
}

// 购物车获取数据
export const ShopCart = () => {
    return requests({ url: "/cart/cartList", method: 'GET' })
}
//购物车切换前面的选中框
export const isChecked = (skuID, isChecked) => {
    return requests({ url: `/cart/checkCart/${skuID}/${isChecked}`, method: 'GET' })
}


// 购物车删除请求
export const deletes = (skuId) => {
    return requests({ url: `/cart/deleteCart/${skuId}`, method: "DELETE" })
}

//获取注册验证码
export const SendCode = (phone) => {
    return requests({ url: `/user/passport/sendCode/${phone}`, method: 'GET' })
}


//注册的接口
//phone	string	Y	注册手机号
//password	string	Y	密码
//code	string	Y	验证码
export const register = (data) => {
    return requests({ url: "/user/passport/register", method: "POST", data })
}


// 登录接口
export const LoginInterface = (user) => {
    return requests({ url: "/user/passport/login", method: 'POST', data: user })
}


//根据token来获取用户信息
export const reqUseInfo = () => {
    return requests({ url: "/user/passport/auth/getUserInfo", method: 'GET' })
}

//退出登录的请求
export const reqlogout = () => {
    return requests({ url: '/user/passport/logout', method: 'GET' })
}


//获取与确定订单信未提交
export const reqtrade = () => {
    return requests({ url: '/order/auth/trade', method: 'GET' });
}


//提交订单获取订单号       /api/order/auth/submitOrder?tradeNo={tradeNo}     POST

// 参数traderNo	string	Y	订单编号(拼接在路径中)
// consignee	string	Y	收件人姓名
// consigneeTel	string	Y	收件人电话
// deliveryAddress	string	Y	收件地址
// paymentWay	string	Y	支付方式
//     (ONLINE代表在线)
// orderComment	string	Y	订单备注
// orderDetailList	Array	Y	存储多个商品对象的数组



export const reqtradeNo = (tradeNo, data) => {
    return requests({ url: `/order/auth/submitOrder?tradeNo=${tradeNo}`, method: 'POST', data })
}

//获取订单支付信息
// /api/payment / weixin / createNative / { orderId }
export const reqcreateNative = (orderId) => {
    return requests({ url: `/payment/weixin/createNative/${orderId}`, method: "GET" })
}


//获取订单的支付状态            /payment/weixin/queryPayStatus/{orderId},
//这个是要一直发的请求
export const reqqueryPay = (orderId) => {
    return requests({ url: `/payment/weixin/queryPayStatus/${orderId}`, method: 'GET' })
}



//获取所有订单          /order/auth/{page}/{limit}          GET请求             page是页数，limit是显示多少数据
export const reqauthpage = (page, limit) => {
    return requests({ url: `/order/auth/${page}/${limit}`, method: 'GET' });
}


//获取订单交易页信息
export const reqtradeauth = () => {
    return requests({ url: "/order/auth/trade", method: "GET" })
}












